import { defineStore } from "pinia";
import { store } from "@/store";

interface CommonState {
  imagesList: Object;
}

export const useCommonStore = defineStore({
  id: "app-common",
  state: (): CommonState => ({
    imagesList: localStorage.getItem("imagesList") ? JSON.parse(localStorage.getItem("imagesList") + "") : {},
  }),

  actions: {
    updateImages(val: Object) {
      this.imagesList = val;
      localStorage.setItem("imagesList", JSON.stringify(val));
    },
  },
});

// Need to be used outside the setup
export function useCommonStoreWithOut() {
  return useCommonStore(store);
}
